package designMode.commandPattern;

/**
 * @ClassName SimpleRemoteControl
 * @Description 控制器
 * @Author LIBOFEI
 * @Date 2020/6/24 21:49
 * @Version 1.0
 **/
public class SimpleRemoteControl {

    Command[] onCommands;
    Command[] offCommands;
    Command undo;

    public SimpleRemoteControl(){
        onCommands = new Command[3];
        offCommands = new Command[3];
        Command command = new NoCommand();
        for(int i  = 0 ; i < 3;i++){
            onCommands[i] = command;
            offCommands[i] = command;
        }
        undo = command;
    }

    public void setCommond(int index,Command onCommand,Command offCommand) {
        onCommands[index] = onCommand;
        offCommands[index] = offCommand;
    }

    public void onButtonWasPushed(int index){
       onCommands[index].execute();
       undo = onCommands[index];
    }

    public void offButtonWasPushed(int index){
        offCommands[index].execute();
        undo = offCommands[index];
    }

    public void undoButtonWasPushes(){
        undo.undo();
    }
}
